package com.jianwei.web.service;

import java.util.List;

import net.sf.json.JSON;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.jianwei.web.dao.LdwsUserDao;
import com.jianwei.web.pojo.LdwsUsers;
import com.jianwei.web.util.DESUtil;

@Component
@Transactional
public class LdwsUserService {
	@Autowired
	private LdwsUserDao ldwsUserDao;
	
	public JSON check(LdwsUsers user){
		String name = "";
		String pwd = "";
		try {
			DESUtil des = new DESUtil("SASGAS");
			name = user.getUsername();
			pwd = des.encrypt(user.getPasswd());
		} catch (Exception e) {
			e.printStackTrace();
		}
		List<LdwsUsers> list = ldwsUserDao.findByParam("From LdwsUsers where username = ? and passwd = ?", name,pwd);
		if(!list.isEmpty() && list.size() == 1){
			JSON json = JSONObject.fromObject("{\"msg\":\"OK\"}");
			return json;
		}
		return JSONObject.fromObject("{\"msg\":\"UserName or Password Fail!\"}");
	}
}
